package com.tang.config;

import lombok.Data;

/**
 * @author JH
 */
@Data
public class ResultData<T> {
    private Integer status;
    private String message;
    private T data;
    private Long timestamp;

    public static <T> ResultData<T> ok(T data){
        ResultData<T> result = new ResultData<>();
        result.setStatus(200);
        result.setMessage("success");
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultData<T> ok(){
        return ok(null);
    }

    public static <T> ResultData<T> fail(Integer status,String message,T data){
        ResultData<T> result = new ResultData<>();
        result.setStatus(status);
        result.setMessage(message);
        result.setTimestamp(System.currentTimeMillis());
        result.setData(data);
        return result;
    }

    public static <T> ResultData<T> fail(Integer status,String message){
        return fail(status,message,null);
    }
}
